package com.ruoyi.web.controller.djb;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.djb.domain.DjbTrade;
import com.ruoyi.djb.service.IDjbTradeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 交易记录Controller
 * 
 * @author xxd
 * @date 2025-03-04
 */
@Controller
@RequestMapping("/djb/djbTrade")
public class DjbTradeController extends BaseController
{
    private String prefix = "djb/djbTrade";

    @Autowired
    private IDjbTradeService djbTradeService;

    @RequiresPermissions("djb:djbTrade:view")
    @GetMapping()
    public String djbTrade()
    {
        return prefix + "/djbTrade";
    }

    /**
     * 查询交易记录列表
     */
    @RequiresPermissions("djb:djbTrade:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DjbTrade djbTrade)
    {
        startPage();
        List<DjbTrade> list = djbTradeService.selectDjbTradeList(djbTrade);
        return getDataTable(list);
    }

    /**
     * 导出交易记录列表
     */
    @RequiresPermissions("djb:djbTrade:export")
    @Log(title = "交易记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DjbTrade djbTrade)
    {
        List<DjbTrade> list = djbTradeService.selectDjbTradeList(djbTrade);
        ExcelUtil<DjbTrade> util = new ExcelUtil<DjbTrade>(DjbTrade.class);
        return util.exportExcel(list, "交易记录数据");
    }

    /**
     * 新增交易记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存交易记录
     */
    @RequiresPermissions("djb:djbTrade:add")
    @Log(title = "交易记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DjbTrade djbTrade)
    {
        return toAjax(djbTradeService.insertDjbTrade(djbTrade));
    }

    /**
     * 修改交易记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        DjbTrade djbTrade = djbTradeService.selectDjbTradeById(id);
        mmap.put("djbTrade", djbTrade);
        return prefix + "/edit";
    }

    /**
     * 修改保存交易记录
     */
    @RequiresPermissions("djb:djbTrade:edit")
    @Log(title = "交易记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DjbTrade djbTrade)
    {
        return toAjax(djbTradeService.updateDjbTrade(djbTrade));
    }

    /**
     * 删除交易记录
     */
    @RequiresPermissions("djb:djbTrade:remove")
    @Log(title = "交易记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(djbTradeService.deleteDjbTradeByIds(ids));
    }
}
